{% extends "howto" %}

{% block main %}
<h2>Adding unit tests</h2>

<p>You can add unit tests to your kits and execute them from the admin interface.</p>

<ol>
    <li>
        <p>Write test cases and put them somewhere into your kit. A <q>tests/</q> folder would be nice. Webappkit currently only support <a href="http://simpletest.org" class="link">Simple Test</a>, but other tests frameworks may be added in the future.</p>
    </li>
    <li>
        <p>Edit your kit config's file to add a <q>tests</q> tool as below :</p>
        <code>[tools]
<var>tests</var> = "SimpleTestTool"</code>
    </li>
    <li>
        <p>Create a <q>tests.tool.ini</q> file at the root of the kit (just as for any tool's config file) And list your test cases as below :</p>
        <code>[classes]
; test_case_class = "path/to/file"
firsttestcase = "tests/first.php"
secondtestcase = "tests/second.php*"</code>
        <p>As you see, you can use the <q>.php*</q> trick to have separate test cases for each php version.</p>
    </li>
    <li>
        <p>Go on your kit's admin page on the admin interface to see unit tests results.</p>
    </li>
</ol>

<h3>With a testing database</h3>

<p>Sometimes you want to test code that use a database. If you don't want to use mock up and don't want to mess you real data either, <q>SimpleTestMysqlTool</q> is for you. It is located within <q>webappkit.simpletest.mysql</q> kit.</p>

<ol>
    <li>
        <p>Write your test cases as above.</p>
    </li>
    <li>
        <p>Edit your kit's config file as below :</p>
        <code>[load_kits]
n = "webappkit.simpletest.mysql"

[tools]
tests = "SimpleTestMysqlTool"</code>
    </li>
    <li>
        <p>Just as above, create a <q>tests.tool.ini</q> file and list your test cases. But you can also set a database connection, and put tables and data creation SQL queries that will be executed before your tests to set up the testing environment.</p>
        <code>[classes]
; your test cases there

[db]
host = "localhost"
user = ""
pwd = ""
name = "unit_tests"
; unit tests database name
encoding = "utf8"
; character encoding for database creation and connexion
create = 1
; if true, will try to create the database
drop = 0
; if true, will drop the database after tests

[tables]
table_name = "Table creation SQL query"
; set your table creation queries there.
; BE CAREFUL ! Those tables will be dropped each time you start your tests !

[data]
n = "Data row creation SQL query"</code>
    </li>
    <li><p>Go the kit's page to execute tests as above</p></li>
</ol>
{% endblock %}
